package com.jt.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import redis.clients.jedis.*;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Configuration
@PropertySource("classpath:/redis.properties")
public class RedisConfig {
   /*@Value("${redis.host}")
    private String hp;

   @Bean
    public ShardedJedis jedisShardInfo(){
       List<JedisShardInfo> jedisList=new ArrayList<>();

       String[] temp1=hp.split(",");
       for (String t:temp1){
           String host=t.split(":")[0];
           int port=Integer.parseInt(t.split(":")[1]);

           jedisList.add(new JedisShardInfo(host,port));

       }
       return new ShardedJedis(jedisList);
   }*/
  /* @Value("${redis.sentinel}")
   private String sentinel;

   @Bean
    public JedisSentinelPool sentinelPool(){
       Set<String> set=new HashSet<>();
       set.add("192.168.126.129:26379");

       JedisSentinelPool sentinelPool=new JedisSentinelPool("mymaster", set);
       JedisPoolConfig jedisPoolConfig=new JedisPoolConfig();
       jedisPoolConfig.setMinIdle(5);
       jedisPoolConfig.setMinIdle(10);
       jedisPoolConfig.setMaxTotal(100);
       return  sentinelPool;
   }*/
  @Value("${redis.cluster}")
  private String hp;

  @Bean
   public JedisCluster jedisCluster(){
     Set<HostAndPort> jedisList=new HashSet<>();
     String[] temp1=hp.split(",");
     for (String t:temp1){
        String host=t.split(":")[0];
        int port=Integer.parseInt(t.split(":")[1]);

        jedisList.add(new HostAndPort(host, port));

     }
     return new JedisCluster(jedisList);

  }




}
